'use strict'

define(['jquery', 'bootstrap', 'bootstrapTable', 'bootstrapTableCN', 'datetimepicker', 'datetimepickerCN', 'select2', 'validate', 'validate.en', 'shiftform',], function($) {
  
  return {
        
    init: function(data) {
        this.initPage(data.today);
        this.exportReport();
    },
    
    initPage: function(date, site, period, today){
        $('select[name="siteId"]').select2({
            minimumResultsForSearch : -1,
            allowClear : true,
            width: '150'
        });

          $('select[name="siteId"]').change(function(){ 

            var site = $(this).children('option:selected').val();
            window.location.href = window.__CTX__.root + "/signin-reports?siteId=" + site;

          })
          
        $('select[name="coachId"]').select2({
            minimumResultsForSearch : 5,
            allowClear : true
        });
          
          $('.date').datetimepicker({
              format: 'yyyy-mm-dd',
              autoclose: true,
              language: 'zh-CN',
              todayBtn: 'linked',
              todayHighlight: true,
              pickerPosition: 'bottom-right',
              minView: 'month',
              startDate: '2018-03-17',
              endDate: today
            });
    },
    
    exportReport: function() {
        $(document).on('shown.bs.modal', '#report-export', function(e){
            $(e.currentTarget).find('form[data-validate="true"]').bt_validate();  //bind validate

            $('button[type="submit"').click(function() {
                $(e.currentTarget).find("form").trigger("validate.ajax.submit");
                $.bt_validate.result[$.bt_validate.form_id];
            });
        });
    },
  }
})
